import {savePrescription, selectPrescription} from "../../api";

let state = {
    configObj:null,
    defaultConfigObj:{
        labor:{
            helmet: {name: "安全帽", indate: 78624000000},    //两年半
            fluorescentClothes: {name: "荧光衣", indate: 63072000000},    //两年
            fingerShoes: {name: "护趾鞋", indate: 63072000000},    //两年
            safetyShoes: {name: "安全鞋", indate: 63072000000},     //两年
        },
        certificate:{
            dyfs: {name: "低压电工证复审", indate: 94608000000},    //3年
            dy: {name: "低压电工证", indate: 189216000000},    //6年
            dg: {name: "登高作业证", indate: 63072000000},
            cc: {name: "叉车作业证", indate: 63072000000},
        },
        others:{
            staffManagementShow: {name: "赋予工班添加员工的权限", value: false},
        }
    }
    // 下面的别删除以后可以打开直接用
    // configObj: {
    //     equip:{
    //         antisquashyShoes: {name: "护趾鞋", indate: 63072000000},
    //         helmet: {name: "安全帽", indate: 78624000000},
    //         insulatedShoes: {name: "绝缘鞋", indate: 63072000000},
    //         reflectiveVest: {name: "荧光衣", indate: 63072000000},
    //     },
    //     certificate:{
    //         lowVoltageCertification:{name:"低压电工证",indate: 94608000000},
    //         highWorkCertificate:{name:"高处作业证",indate: 94608000000},
    //     },
    //     examination:{
    //         againTrain:{name:"复训",indate: 31536000000},
    //     },
    //     otherConfig:{
    //         exportPath:{name:"导出路径",value:"",type:"string"},
    //     },
    //
    //     timeout:[
    //         {time:2626560000,color:"#115566"},
    //         {time:2626560000,color:"#115566#115566"},
    //         {time:2626560000,color:"#115566"},
    //     ]
    //     // antisquashyShoes: {name: "护趾鞋", indate: 63072000000},
    //     // helmet: {name: "安全帽", indate: 78624000000},
    //     // insulatedShoes: {name: "绝缘鞋", indate: 63072000000},
    //     // reflectiveVest: {name: "荧光衣", indate: 63072000000}
    // }
}
const mutations = {
    SaveConfig (state,data) {
        state.configObj = data;
    }
}
const actions = {
    /*读取配置*/
    async selectPrescriptionFun({commit}) {
        commit('SaveConfig', state.defaultConfigObj);
        selectPrescription().then((res) => {
            if(res.code === 200){
                commit('SaveConfig', res.prescriptionData);
                console.log(res);
            }else{
                ElNotification({
                    title: 'OK!',
                    message: '读取配置失败,加载默认配置!',
                    duration: 1000,
                    position: 'bottom-right',
                });
                commit('SaveConfig', state.defaultConfigObj);
                console.log(res);
            }
        },(error)=>{
            commit('SaveConfig', state.defaultConfigObj);
            console.log(error);
        });
    },
    /*保存配置*/
    async savePrescriptionFun({commit},configData) {
        let data = {
            prescriptionData: JSON.stringify(configData)
        }
        savePrescription(data).then((res) => {
            if(res.code === 200){
                ElNotification({
                    title: 'OK!',
                    message: '保存配置成功',
                    duration: 1000,
                    position: 'bottom-right',
                    type: 'success',

                });
                commit('SaveConfig', configData);
                console.log(res);
            }else{
                console.log(res);
            }
        },(error)=>{
            console.log(error);
        });
    },
    /*恢复默认配置*/
    async saveDefaultConfigFun({commit}) {
        let data = {
            prescriptionData: JSON.stringify(state.defaultConfigObj)
        }
        savePrescription(data).then((res) => {
            if(res.code === 200){
                ElNotification({
                    title: 'OK!',
                    message: '恢复默认设置成功',
                    duration: 1000,
                    position: 'bottom-right',
                    type: 'success',
                });
                commit('SaveConfig', state.defaultConfigObj);
                console.log(res);
            }else{
                console.log(res);
            }
        },(error)=>{
            console.log(error);
        });
    }
}
const getters = {};
export default {
    namespaced:true,
    state,
    mutations,
    actions,
    getters,
};
